 package server.console.groups.setting;

 import com.alee.extended.panel.GroupPanel;
 import com.alee.laf.checkbox.WebCheckBox;
 import com.alee.laf.combobox.WebComboBox;
 import com.alee.laf.label.WebLabel;
 import com.alee.laf.panel.WebPanel;
 import com.alee.laf.separator.WebSeparator;
 import com.alee.laf.text.WebTextField;
 import configs.Config;
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.util.HashMap;
 import java.util.Map;
 import javax.swing.AbstractAction;
 import javax.swing.ImageIcon;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import server.console.Start;

 public abstract class AbstractConfigGroup implements ConfigGroup {
/*  23 */   private static final Map<String, ImageIcon> iconsCache = new HashMap<>();
   protected final ConfigPanel owner;
   protected final String titleText;

   AbstractConfigGroup(ConfigPanel owner, String titleText) {
/*  28 */     this.owner = owner;
/*  29 */     this.titleText = titleText;
   }


   public String toString() {
/*  34 */     return this.titleText;
   }

   public ImageIcon loadIcon(String path) {
/*  38 */     String key = Start.class.getCanonicalName() + ":" + path;
/*  39 */     if (!iconsCache.containsKey(key)) {
/*  40 */       iconsCache.put(key, new ImageIcon(getClass().getResource("/icon/" + path)));
     }
/*  42 */     return iconsCache.get(key);
   }

   class TitleWebPanel
     extends WebPanel {
     private final String titleText;

     TitleWebPanel(String titleText) {
/*  50 */       this.titleText = titleText;
/*  51 */       setMargin(15, 15, 0, 15);
/*  52 */       WebPanel north = new WebPanel(new BorderLayout());
/*  53 */       north.add((Component)(new WebLabel(titleText)).setFontSizeAndStyle(14, false, false), "West");
/*  54 */       WebSeparator separator = new WebSeparator(false, false);
/*  55 */       separator.setSeparatorUpperColor(separator.getSeparatorColor());
/*  56 */       separator.setMargin(9, 5, 0, 0);
/*  57 */       north.add((Component)separator, "Center");
/*  58 */       add((Component)north, "North");
     }

     public String getTitleText() {
/*  62 */       return this.titleText;
     }
   }

   class ConfigComponent
     extends GroupPanel {
     ConfigComponent(String labelName) {
/*  69 */       this(labelName, ConfigGroup.ComponentType.编辑框);
     }

     ConfigComponent(String labelName, String settingname) {
/*  73 */       this(labelName, ConfigGroup.ComponentType.编辑框, settingname);
     }

     ConfigComponent(String labelName, ConfigGroup.ComponentType componentType) {
/*  77 */       this(labelName, componentType, "");
     }

     ConfigComponent(String labelName, ConfigGroup.ComponentType componentType, String settingname) {
/*  81 */       this(labelName, componentType, settingname, "");
     }
     ConfigComponent(String labelName, ConfigGroup.ComponentType componentType, final String settingname, String defCombo) {
/*  84 */       super(new Component[0]); WebLabel webLabel1; WebCheckBox checkBox; WebLabel label; final WebTextField textField; final WebComboBox comboBox;
/*  85 */       switch (componentType) {
         case 编辑框:
/*  87 */           webLabel1 = new WebLabel(labelName + ": ", 4, new Object[0]);
/*  88 */           webLabel1.setPreferredWidth(150);
/*  89 */           add((Component)webLabel1);

/*  91 */           textField = (new WebTextField(30)).setPreferredWidth(200);
/*  92 */           if (!settingname.isEmpty()) {
/*  93 */             textField.setText(Config.getProperty(settingname, ""));
           }
/*  95 */           textField.getDocument().addDocumentListener(new DocumentListener()
               {
                 public void insertUpdate(DocumentEvent e) {
/*  98 */                   AbstractConfigGroup.this.owner.getWebButtonApply().setEnabled(true);
/*  99 */                   AbstractConfigGroup.this.owner.getChangeSettingQueue().put(settingname, textField.getText().replace("\\", "/"));
                 }


                 public void removeUpdate(DocumentEvent e) {
/* 104 */                   AbstractConfigGroup.this.owner.getWebButtonApply().setEnabled(true);
/* 105 */                   AbstractConfigGroup.this.owner.getChangeSettingQueue().put(settingname, textField.getText().replace("\\", "/"));
                 }


                 public void changedUpdate(DocumentEvent e) {
/* 110 */                   System.out.println(textField.getText().replace("\\", "/"));
                 }
               });
/* 113 */           add((Component)textField);
           break;

         case 复选框:
/* 117 */           checkBox = new WebCheckBox(labelName);
/* 118 */           if (!settingname.isEmpty()) {
/* 119 */             checkBox.setSelected(Boolean.valueOf(Config.getProperty(settingname, "false")).booleanValue());
           } else {
/* 121 */             checkBox.setEnabled(false);
           }
/* 123 */           checkBox.setMargin(3, 20, 0, 0);
/* 124 */           checkBox.addActionListener(e -> {
                 AbstractConfigGroup.this.owner.getWebButtonApply().setEnabled(true);
                 AbstractConfigGroup.this.owner.getChangeSettingQueue().put(settingname, String.valueOf(checkBox.isSelected()));
               });
/* 128 */           add((Component)checkBox);
           break;

         case 下拉菜单:
/* 132 */           label = new WebLabel(labelName + ": ", 4, new Object[0]);
/* 133 */           label.setPreferredWidth(150);
/* 134 */           add((Component)label);
/* 135 */           comboBox = (new WebComboBox((Object[])defCombo.split(","))).setPreferredWidth(100);
/* 136 */           if (!settingname.isEmpty()) {
/* 137 */             comboBox.setSelectedIndex(Integer.valueOf(Config.getProperty(settingname, "0")).intValue());
           }
/* 139 */           comboBox.addActionListener(new AbstractAction()
               {
                 public void actionPerformed(ActionEvent e) {
/* 142 */                   AbstractConfigGroup.this.owner.getWebButtonApply().setEnabled(true);
/* 143 */                   AbstractConfigGroup.this.owner.getChangeSettingQueue().put(settingname, String.valueOf(comboBox.getSelectedIndex()));
                 }
               });


/* 148 */           add((Component)comboBox);
           break;
       }
     }
   }
 }
